import * as shoppingCartApi from '@/api/shopping.js';

export default {
  namespaced: true,
  state() {
    return {
      // 放大镜
      member: {
        brand: {},
        details: {},
        hotByDay: [],
        mainPictures: [],
        similarProducts: [],
        skus: [],
        specs: [],
        userAddresses: [],
      },

      // 同类商品推荐
      updaterelevantlist: [],
      // 小时热榜
      updategoods: [],
      // 购物车
      getShoppingCartList: [],
      // 获取当前购物车数量
      getShoppingCartListCount: {},
      // 删除购物车
      getShoppingCartListDel: {},
      getShoppingCartLike: [],
    };
  },
  mutations: {
    MEMBER_LIST(state, newValue) {
      state.member = newValue;
    },
    // 同类商品推荐
    RELEVANT(state, newValue) {
      state.updaterelevantlist = newValue;
    },
    GOODS_DETAIL(state, newValue) {
      state.updategoods = newValue;
    },
    SHOPPINGCART_LIST(state, newValue) {
      state.getShoppingCartList = newValue;
    },
    SHOPPINGCART_LIST_COUNT(state, newValue) {
      state.getShoppingCartListCount = newValue;
    },
    SHOPPINGCART_LIST_DELETE(state, newValue) {
      state.getShoppingCartListDel = newValue;
    },
    SHOPPINGCART_LIKE(state, newValue) {
      state.getShoppingCartLike = newValue;
    },

  },
  actions: {
    async updateMember({ commit }, id) {
      const res = await shoppingCartApi.MEMBER(id);
      commit('MEMBER_LIST', res);
    },
    async updateRelevant({ commit }, id) {
      const res = await shoppingCartApi.getRelevant(id);
      commit('RELEVANT', res);
    },
    async updategoodshotlist({ commit }, id) {
      const res = await shoppingCartApi.getGoodsHot(id);
      commit('GOODS_DETAIL', res);
    },
    // 购物车数据
    async updateCart({ commit }) {
      const res = await shoppingCartApi.getCart();
      commit('SHOPPINGCART_LIST', res);
    },
    async addCart({ commit }, params) {
      const res = await shoppingCartApi.addCart(params);
      commit('SHOPPINGCART_LIST_COUNT', res);
    },
    // 猜你喜欢
    async cartLike({ commit }, params) {
      const res = await shoppingCartApi.getGoodsLike(params);
      commit('SHOPPINGCART_LIKE', res);
    },

  },
};
